/**
 * @param {number[]} nums
 * @return {number[]}
 */
var productExceptSelf = function(nums) {
    var left = []
    var right = []
    var arr = []
    for(var i = 0; i < nums.length; i++){
         if(i===0){
             left.push(1)
         }else{
             left.push(left[i-1]*nums[i-1])
         }
 
    }
     for(var i = nums.length-1; i >=0; i--){
         if(i===nums.length-1){
             right.push(1)
         }else{
             right.push(left[i+1]*nums[i+1])
         }
    }
    for(var i=0;i<left.length;i++){
        arr.push(left[i])
    }
 
}
 
 
 
 
 
 
 
 
 /**
 * @param {number[]} nums
 * @return {number[]}
 */
var productExceptSelf = function(nums) {
    var left = []
  
    for(var i = 0; i < nums.length; i++){
        if(i===0){
            left.push(1)
        }else{ 

            left.push(left[i-1] * nums[i-1])
        }
    }

    for(var j = nums.length-1; j >= 0; j--){
         if(j === nums.length-1){
             right[j]=1
         }else{
             right[j]=right[j+1]*nums[j+1]
         }
    }


    for(var k=0;k<left.length;k++){
        arr.push(left[k]*right[k])
    }
    return arr;
}

console.log(productExceptSelf([1,2,3,4]))










